﻿using System;
using System.Collections.Generic;

namespace Freedom.Common.Collections
{
    /// <summary>
    /// The collection surport filter 
    /// </summary>
    public abstract class ObjectFilterCollection<T, T1> : ObjectCollection<T>, IFilter<T1>
        where T : class, ICopiable<T>, IIdentifiable
        where T1: struct, IComparable, IConvertible, IFormattable
    {

        /// <summary>
        /// The filter conditon collection
        /// </summary>
        protected List<ConditionPara<T1>> Condition = new List<ConditionPara<T1>>();

        /// <summary>
        /// clear filter conditions
        /// </summary>
        public void ClearFilterConditions()
        {
            Condition.Clear();
        }

        /// <summary>
        /// Sets the conditions.
        /// </summary>
        /// <param name="newConditions">The new conditions.</param>
        public void SetConditions(IEnumerable<ConditionPara<T1>> newConditions)
        {
            Condition.RemoveAll(i => i.Condition != Collections.Condition.Order);
            Condition.AddRange(newConditions);
        }

        /// <summary>
        /// Sets the sort conditions.
        /// </summary>
        /// <param name="newConditions">The new conditions.</param>
        public void SetSortConditions(IEnumerable<ConditionPara<T1>> newConditions)
        {
            Condition.RemoveAll(i => i.Condition == Collections.Condition.Order);
            Condition.AddRange(newConditions);
        }

        /// <summary>
        /// set a new filter conditions
        /// </summary>
        /// <param name="newConditions"></param>
        public void SetFilterConditions(List<ConditionPara<T1>> newConditions)
        {
            Condition = newConditions;
        }

        /// <summary>
        /// add a filter condtiion
        /// </summary>
        /// <param name="para"></param>
        public void AddFilterCondition(ConditionPara<T1> para)
        {
            Condition.Add(para);
        }

        /// <summary>
        /// Gets the conditions.
        /// </summary>
        /// <returns></returns>
        public List<ConditionPara<T1>> GetConditions()
        {
            return Condition;
        }
    }
}
